#include<bits/stdc++.h>
#define int long long
using namespace std;
struct Edge{int a,b,c,l,r;}x[100005];
struct node{int l,r;}t[100005];
priority_queue<int>q;
int z[1000005],w[100005],n,m,summ,L,V;
bool cmp(node a,node b){return a.l<b.l;}
int lowbit(int now){return now&-now;}
void up(int now){
    for(int i=now;i<=L;i+=lowbit(i))z[i]++;
    return;
}
int down(int now){
    int ans=0;
    for(int i=now;i;i-=lowbit(i))ans+=z[i];
    return ans;
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%lld",&T);
    while(T--){
        summ=0;
        scanf("%lld%lld%lld%lld",&n,&m,&L,&V);
        L++;
        for(int i=1;i<=L;i++)z[i]=0;
        for(int i=1;i<=n;i++){
            x[i].l=x[i].r=0;
            int a,b,c;
            scanf("%lld%lld%lld",&a,&b,&c);
            a++;
            x[i].a=a;
            x[i].b=b;
            x[i].c=c;
            if(c>0){
                if(b*b+2*c*(L-a)<=V*V)continue;
                int l=0,r=L-a;
                while(l<r){
                    int mid=(l+r)/2;
                    if(b*b+2*c*mid>V*V)r=mid;
                    else l=mid+1;
                }
                x[i].l=a+l;
                x[i].r=L;
            }
            else{
                if(b<=V)continue;
                int l=0,r=L-a;
                while(l<r){
                    int mid=(l+r)/2+(l+r)%2;
                    if(b*b+2*c*mid>V*V)l=mid;
                    else r=mid-1;
                }
                x[i].l=a;
                x[i].r=a+l;
            }
        }
        int ans=0;
        for(int i=1;i<=m;i++){
            scanf("%lld",&w[i]);
            w[i]++;
            up(w[i]);
        }
        int top=0;
        for(int i=1;i<=n;i++)if(x[i].l&&x[i].r&&down(x[i].r)-down(x[i].l-1)>0){
            summ++;
            t[++top].l=x[i].l;
            t[top].r=x[i].r;
        }
        w[m+1]=1e9;
        int lef=1;
        sort(t+1,t+top+1,cmp);
        while(!q.empty())q.pop();
        for(int i=1;i<=m;i++){
            while(lef<=top&&t[lef].l<=w[i]){
                q.push(-t[lef].r);
                lef++;
            }
            if(!q.empty()&&-q.top()<w[i+1]){
                ans++;
                while(!q.empty())q.pop();
            }
        }
        printf("%lld %lld\n",summ,m-ans);
    }
    return 0;
}